package com.example.demo.controller;

import com.example.demo.service.MessageService;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class MessageController {

    @Resource
    private MessageService messageService;

    @MessageMapping("/demand")
    public void  messageMatch(){
        messageService.produceAndExport();
        messageService.generateMessage();
//        while (!messageService.can_be_done_or_not()){
//        messageService.driverChoose();}
//        messageService.accept_refused_cars();
//        return ResponseEntity.ok(messageService.queryMessages());
        while (!messageService.can_be_done_or_not()){
            messageService.factoriesAndCarChoose2();
        }
    }

    @MessageMapping("/test")
    public void testing(){
        System.out.println("收到前端的消息");
        Map<String,Object> message = new HashMap<>();
        message.put("message","测试成功");
        messageService.sendMessage(message);
    }
}
